#include <iostream>
using namespace std;
int main(){
    int n,head,rear,res=-1;
    int k[10001],sum[10001];
    cin>>n;
    for (int i = 1; i <= n; i++)
    {
        cin>>k[i];
    }
    sum[0]=0;
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+k[i];
    }
    int lowest=0;
    for(int end=1;end<=n;end++){
        if(sum[end]-sum[lowest]>res){
            res=sum[end]-sum[lowest];
            head=k[lowest+1];
            rear=k[end];
        }
        if(sum[lowest]>sum[end])lowest=end;
    }
    if(res<0)cout<<0<<" "<<k[1]<<" "<<k[n];
    else cout<<res<<" "<<head<<" "<<rear;
}